package D3;

import java.util.Arrays;
import java.util.function.IntToDoubleFunction;

public class Java01 {
    public static void main(String[] args) {
        //新的学习：数据结构与算法
        //Arrays类是操作数组的工具类，可以遍历，拷贝，排序等操作
        //1、tostring返回数组的内容
        int[] arr = new int[]{10,20,30,40,50,60,70,80,90};
        System.out.println(Arrays.toString(arr));
        //2、拷贝数组，抱歉不报后
        int[] arr2 = Arrays.copyOfRange(arr,1,4);
        System.out.println(Arrays.toString(arr2));
        //3、拷贝数组，指定新的数组长度
        int[] arr3 = Arrays.copyOf(arr,10);
        System.out.println(Arrays.toString(arr3));
        //把数组中的元数据改为新数据再插进去
        double[] prices = new double[]{99.8,128,100};
        //把所有的数据打八折再插进去
        Arrays.setAll(prices,(int value) ->{
            return prices[value] * 0.8;
        });
        Arrays.setAll(prices, new IntToDoubleFunction() {
            @Override
            public double applyAsDouble(int value) {
                return prices[value] * 0.8;
            }
        });
        System.out.println(Arrays.toString(prices));
        //5、对数据进行排序操作，默认是升序排序
        Arrays.sort(prices);
        System.out.println(Arrays.toString(prices));
    }
}
